package com.admin.education.models;

import com.admin.education.repositories.Identifiable;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;
import java.util.List;

@Entity
@Table(name = "templates")
@EntityListeners(AuditingEntityListener.class)
@Data
public class Templates  implements Serializable,Identifiable{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    @Column(name = "name")
    @Length(max=1024)
    @NotBlank
    @NotNull
    private String name;
    @OneToMany(cascade = CascadeType.REMOVE,fetch = FetchType.LAZY,mappedBy = "templates")
    @JSONField(serialize=false)
    private List<TemplateQuestions> templateQuestions;
    @OneToMany(mappedBy = "templates",cascade = CascadeType.DETACH)
    @JSONField(serialize=false)
    private List<UserAnswerSheet> userAnswerSheets;
    @ManyToMany()
    @JSONField(serialize=false)
    private List<Categorys> categorys;
    @OneToMany(mappedBy = "templates",cascade = CascadeType.REMOVE)
    @JSONField(serialize = false)
    private List<ApplyCrowd> applyCrowds;
    @Column(name="valid")
    @NotNull
    private boolean valid;
    @Column(name = "template_mark")
    private BigDecimal templateMark;
    @Column(name="create_time")
    private Date createTime;
    @Column(name="modify_time")
    private Date modifyTime;
    @Column(name = "allow_multiple_answer")
    @NotNull
    private boolean allowMultipleAnswer;
    @OneToMany(mappedBy = "templates")
    private List<WaitForChallenges> waitForChallenges;
}
